/*
 *  gvcs-nautilus.c - Version control extension for Nautilus
 * 
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Author: Jack Xu Hong <jack.xu.hong@gmail.com>
 * 
 */

#include <config.h>

#include <libnautilus-extension/nautilus-extension-types.h>
#include <libnautilus-extension/nautilus-column-provider.h>

#include <glib/gi18n-lib.h>

#define GVCS_TYPE_NAUTILUS  (gvcs_nautilus_get_type ())
#define GVCS_NAUTILUS(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), GVCS_TYPE_NAUTILUS, GVcsNautilus))

typedef struct {
	GObject parent;
} GVcsNautilus;

typedef struct {
	GObjectClass parent;
} GVcsNautilusClass;

static GType gvcs_nautilus_get_type      (void);
static void  gvcs_nautilus_register_type (GTypeModule *module);

static GObjectClass *parent_class;

/* nautilus_column_provider_get_columns
 *  
 * This function is called by Nautilus to get the column objects
 * exported by the provider.
 *
 * The function should return a GList of allocated NautilusColumn
 * items.
 */
static GList *
gvcs_nautilus_get_columns (NautilusColumnProvider *provider)
{
	NautilusColumn *column;
	
	column = nautilus_column_new ("GVcsNautilus::version_info_column",
				      "GVcsNautilus::version_info",
				      _("Version Info"),
				      _("Information from the version control system"));
	
	return g_list_append (NULL, column);
}

static void
gvcs_nautilus_column_provider_iface_init (NautilusColumnProviderIface *iface)
{
	iface->get_columns = gvcs_nautilus_get_columns;
}

static void
gvcs_nautilus_instance_init (GVcsNautilus *vcs)
{
}

static void
gvcs_nautilus_class_init (GVcsNautilusClass *class)
{
        parent_class = g_type_class_peek_parent (class);
}

static GType vcs_type = 0;

static GType
gvcs_nautilus_get_type (void)
{
	return vcs_type;
}

static void
gvcs_nautilus_register_type (GTypeModule *module)
{
	static const GTypeInfo info = {
                sizeof (GVcsNautilusClass),
                (GBaseInitFunc) NULL,
                (GBaseFinalizeFunc) NULL,
                (GClassInitFunc) gvcs_nautilus_class_init,
                NULL,
                NULL,
                sizeof (GVcsNautilus),
                0,
                (GInstanceInitFunc) gvcs_nautilus_instance_init,
        };

	static const GInterfaceInfo column_provider_iface_info = {
		(GInterfaceInitFunc) gvcs_nautilus_column_provider_iface_init,
		NULL,
		NULL
	};
	
	vcs_type = g_type_module_register_type (module, 
						G_TYPE_OBJECT,
						"GVcsNautilus",
						&info, 0);
	g_type_module_add_interface (module,
				     vcs_type,
				     NAUTILUS_TYPE_COLUMN_PROVIDER,
				     &column_provider_iface_info);
}

/* Extension module functions.  These functions are defined in 
 * nautilus-extensions-types.h, and must be implemented by all 
 * extensions. */

/* Initialization function.  In addition to any module-specific 
 * initialization, any types implemented by the module should 
 * be registered here. */
void
nautilus_module_initialize (GTypeModule  *module)
{
	g_print ("Initializing gvcs-nautilus extension\n");

	gvcs_nautilus_register_type (module);
}

/* Perform module-specific shutdown. */
void
nautilus_module_shutdown   (void)
{
	g_print ("Shutting down gvcs-nautilus extension\n");
}

/* List all the extension types.  */
void 
nautilus_module_list_types (const GType **types,
			    int          *num_types)
{
	static GType type_list[1];
	
	type_list[0] = GVCS_TYPE_NAUTILUS;

	*types = type_list;
	*num_types = 1;
}
